package com.brooks.demo;

import java.util.concurrent.TimeUnit;

/**
 * 锁的可重入
 *
 * @Author mihutu
 * @Date 2020/10/17 19:18
 * @Version 1.0
 */
public class DemoReentrantLock1 {
    synchronized void m1(){
       for (int i=0;i<10;i++){
           try {
               TimeUnit.SECONDS.sleep(1);
           } catch (InterruptedException e) {
               e.printStackTrace();
           }
           System.out.println(i);
       }
    }
    synchronized void m2(){
        System.out.println("m2====");
    }

    public static void main(String[] args) {
        DemoReentrantLock1 t = new DemoReentrantLock1();
        new Thread(t::m1).start();
        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        new Thread(t::m2).start();
    }
}